package com.warm.androidstudy.view.ratingBar;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.warm.androidstudy.R;


public class StarView extends LinearLayout {
//    @BindView(R.id.iv_star)
//    ImageView ivStar;
//    @BindView(R.id.iv_star2)
//    ImageView ivStar2;
//    @BindView(R.id.iv_star3)
//    ImageView ivStar3;
//    @BindView(R.id.iv_star4)
//    ImageView ivStar4;
//    @BindView(R.id.iv_star5)
//    ImageView ivStar5;
    private ImageView ivStar;
    private ImageView ivStar2;
    private ImageView ivStar3;
    private ImageView ivStar4;
    private ImageView ivStar5;
    private Animation anim;
    private Animation anim2;
    private Animation anim3;
    private Animation anim4;
    private Animation anim5;
    private int type ;

    public StarView(Context context) {
        super(context);
    }

    public StarView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public StarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void init(Context context) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.adapter_star, this);
        ivStar = view.findViewById(R.id.iv_star);
        ivStar2 = view.findViewById(R.id.iv_star2);
        ivStar3 = view.findViewById(R.id.iv_star3);
        ivStar4 = view.findViewById(R.id.iv_star4);
        ivStar5 = view.findViewById(R.id.iv_star5);
        anim = AnimationUtils.loadAnimation(context, R.anim.star_scale);
        anim2 = AnimationUtils.loadAnimation(context, R.anim.star_scale);
        anim3 = AnimationUtils.loadAnimation(context, R.anim.star_scale);
        anim4 = AnimationUtils.loadAnimation(context, R.anim.star_scale);
        anim5 = AnimationUtils.loadAnimation(context, R.anim.star_scale);



    }

    public void setAnim(int type) {
        if (type == 1) {
            ivStar.setImageResource(R.drawable.icon_score_select);
            ivStar.startAnimation(anim);
            anim.setFillAfter(true);

        }
        if (type == 2) {
            ivStar2.setImageResource(R.drawable.icon_score_select);
            ivStar2.startAnimation(anim2);
            anim2.setFillAfter(true);
        }
        if (type == 3) {
            ivStar3.setImageResource(R.drawable.icon_score_select);
            ivStar3.startAnimation(anim3);
            anim3.setFillAfter(true);
        }
        if (type == 4) {
            ivStar4.setImageResource(R.drawable.icon_score_select);
            ivStar4.startAnimation(anim4);
            anim4.setFillAfter(true);
        }
        if (type == 5) {
            ivStar5.setImageResource(R.drawable.icon_score_select);
            ivStar5.startAnimation(anim5);
            anim5.setFillAfter(true);
        }

    }
}
